<%@ page import="cn.edu.hwec.DBHelper" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>DBHelper的使用</title>
    <style>
        h1{
            color:red;
        }
        table{
            border: 3px solid red;
            border-spacing: 0;
        }
        th,td{
            border-right: 1px dotted red;
            border-bottom: 1px dotted red;
            padding: 6px 10px;
        }
    </style>
</head>
<body>
<h1>利用DBHelper进行数据库操作</h1>
<table>
    <%
        List<Map<String, Object>> cys = DBHelper.query("select * from chengyu limit ?,?", 2,5);//Ctrl+Alt+V 将表达式保存到一个局部变量中
        out.print("<tr>");
        Iterator<Map.Entry<String, Object>> it = cys.getFirst().entrySet().iterator();
        while(it.hasNext()){
            out.print("<th>"+it.next().getKey()+"</th>");
        }
        out.print("</tr>");
        for(Map<String, Object> row :cys){
            out.print("<tr>");
            Iterator<Map.Entry<String, Object>> iterator = row.entrySet().iterator();
            while(iterator.hasNext()){
                Map.Entry<String, Object> entry = iterator.next();
                String key = entry.getKey();
                Object value = entry.getValue();
                out.print("<td>"+value+"</td>");
            }
            out.print("</tr>");
        }
    %>
</table>
</body>
</html>
//